//
//  RGLoginWithPassView.m
//  RedGrass
//
//  Created by wukong on 2018/12/10.
//  Copyright © 2018年 hongcaosp. All rights reserved.
//

#import "RGLoginWithPassView.h"
#import "HALoginWithPassNavView.h"

@interface RGLoginWithPassView()

@property (strong, nonatomic) UIScrollView *scrollView1;
@property (strong, nonatomic) UIView *containerView1;
@property (strong, nonatomic) UIImageView *bgImg;
@property (strong, nonatomic) UIView *loginView;// 登录页面
@property (strong, nonatomic) UILabel *alertLabel1;
@property (strong, nonatomic) UIView *bgView4;
@property (strong, nonatomic) UIImageView *bgImg4;
@property (strong, nonatomic) UILabel *areaLabel1;
@property (strong, nonatomic) UIImageView *areaImg1;
@property (strong, nonatomic) UITextField *phoneTF1;
@property (strong, nonatomic) UIView *bgView5;
@property (strong, nonatomic) UIImageView *bgImg5;
@property (strong, nonatomic) UITextField *passWordTF;
@property (strong, nonatomic) UIButton *loginBtn;
@property (strong, nonatomic) UIButton *forgetPassBtn;
//@property (strong, nonatomic) HALoginWithPassNavView *loginWithPassNavView;

@end

@implementation RGLoginWithPassView


-(instancetype) initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        [self initUI];
        [self initLoginViewUI];
    }
    return self;
}

-(void)initUI{
    
    [self addSubview:self.bgImg];
    [_bgImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
    [self addSubview:self.loginView];
    [_loginView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
}

//登录UI
-(void) initLoginViewUI{
    [_loginView addSubview:self.scrollView1];
//    [_loginView addSubview:self.loginWithPassNavView];
    [self.scrollView1 addSubview:self.containerView1];
    [self loginViewAddMasonry];
    [self initLoginContainerView];
}

-(void) initLoginContainerView{
    
    AA_WEAK_MAKE(self)weakSelf = self;
    [_containerView1 addSubview:self.alertLabel1];
    [_alertLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.containerView1.mas_top).mas_offset(310);
        make.centerX.mas_equalTo(weakSelf.containerView1).mas_offset(0);
        make.height.mas_equalTo(30);
        
    }];
    
    [_containerView1 addSubview:self.bgView4];
    [_bgView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.alertLabel1.mas_bottom).mas_offset(12);
        make.centerX.mas_equalTo(weakSelf.containerView1).mas_offset(0);
        make.left.mas_equalTo(weakSelf.containerView1).mas_offset(40);
        make.height.mas_equalTo(60);
    }];
    
    [_containerView1 addSubview:self.bgView5];
    [_bgView5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.bgView4.mas_bottom).mas_offset(4);
        make.centerX.mas_equalTo(weakSelf.containerView1).mas_offset(0);
        make.left.mas_equalTo(weakSelf.containerView1).mas_offset(40);
        make.height.mas_equalTo(60);
    }];
    
    [_containerView1 addSubview:self.loginBtn];
    [_loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.bgView5.mas_bottom).mas_offset(12);
        make.centerX.mas_equalTo(weakSelf.containerView1).mas_offset(0);
        make.left.mas_equalTo(weakSelf.containerView1).mas_offset(48);
        make.height.mas_equalTo(44);
    }];
    
    [_containerView1 addSubview:self.forgetPassBtn];
    [_forgetPassBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        //        make.top.mas_equalTo(weakSelf.weChatLoginBtn.mas_bottom).mas_offset(40).with.priority(250);
        make.top.mas_equalTo(weakSelf.loginBtn.mas_bottom).mas_offset(12);
        make.height.mas_equalTo(30);
        make.centerX.mas_equalTo(weakSelf.containerView1).mas_offset(0);
        make.bottom.mas_equalTo(weakSelf.containerView1.mas_bottom).mas_offset(-60).with.priority(250);
    }];
    
    [self initBgView4];
    [self initBgView5];
}

-(void) loginViewAddMasonry{
    [_scrollView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
    [_containerView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
        make.width.mas_equalTo(self.scrollView1).mas_offset(0);
        make.height.mas_greaterThanOrEqualTo(KScreenHeight);
    }];
//    [_loginWithPassNavView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(self).mas_offset(60);
//        make.left.and.right.mas_equalTo(self).mas_offset(0);
//        make.height.mas_equalTo(44);
//    }];
}

-(void)initBgView4{
    [_bgView4 addSubview:self.bgImg4];
    [_bgImg4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
    AA_WEAK_MAKE(self) weakSelf = self;
    [_bgView4 addSubview:self.areaLabel1];
    [_areaLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.bgView4).mas_offset(-4);
        make.left.mas_equalTo(weakSelf.bgView4).mas_offset(22);
        make.width.mas_equalTo(35);
    }];
    
    [_bgView4 addSubview:self.areaImg1];
    [_areaImg1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.bgView4).mas_offset(-4);
        make.left.mas_equalTo(weakSelf.areaLabel1.mas_right).mas_offset(1);
        make.size.mas_equalTo(CGSizeMake(10, 6));
    }];
    [_bgView4 addSubview:self.phoneTF1];
    [_phoneTF1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.bgView4).mas_offset(-4);
        make.left.mas_equalTo(weakSelf.areaImg1.mas_right).mas_offset(6);
        make.height.mas_equalTo(26);
        make.right.mas_equalTo(weakSelf.bgView4).mas_offset(-8);
    }];
}

-(void)initBgView5{
    [_bgView5 addSubview:self.bgImg5];
    [_bgImg5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
    AA_WEAK_MAKE(self) weakSelf = self;
    [_bgView5 addSubview:self.passWordTF];
    [_passWordTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.bgView5).mas_offset(-4);
        make.left.mas_equalTo(weakSelf.bgView5).mas_offset(22);
        make.height.mas_equalTo(26);
        make.right.mas_equalTo(weakSelf.bgView5).mas_offset(-12);
    }];
}

#pragma mark - reponse
-(void)loginBtnClick:(UIButton *) button{
    if([self.viewDeleagte respondsToSelector:@selector(loginWithPassword:phone:)]){
        [self.viewDeleagte loginWithPassword:self.passWordTF.text phone:self.phoneTF1.text];
    }
}

-(void)forgetPassBtnClick:(UIButton *) button{
    if([self.viewDeleagte respondsToSelector:@selector(resetPasswordWithView:phone:)]){
        [self.viewDeleagte resetPasswordWithView:self phone:self.phoneTF1.text];
    }
}

#pragma mark - getter

-(UIView *)loginView{
    if(!_loginView){
        _loginView = [[UIView alloc]init];
    }
    return _loginView;
}

-(UIScrollView *)scrollView1{
    if(!_scrollView1){
        _scrollView1 = [[UIScrollView alloc]init];
    }
    return _scrollView1;
}

-(UIImageView *)bgImg{
    if(!_bgImg){
        _bgImg = [[UIImageView alloc]init];
        _bgImg.image = IMAGE_NAMED(@"bj");
        //        _bgImg.contentMode = UIViewContentModeCenter;
    }
    return _bgImg;
}

-(UIView *)containerView1{
    if(!_containerView1){
        _containerView1 = [[UIView alloc]init];
    }
    return _containerView1;
}

//-(HALoginWithPassNavView *)loginWithPassNavView{
//    if(!_loginWithPassNavView){
//        _loginWithPassNavView = [[HALoginWithPassNavView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
//    }
//    return _loginWithPassNavView;
//}

-(UILabel *)alertLabel1{
    if(!_alertLabel1){
        _alertLabel1 = [[UILabel alloc]init];
        _alertLabel1.textColor = CFontColor2;
        _alertLabel1.text = @"手机号登录有助于您快速找到朋友";
        _alertLabel1.font = FONT(customFontName, 14);
        _alertLabel1.textAlignment = NSTextAlignmentCenter;
    }
    return _alertLabel1;
}

-(UIView *)bgView4{
    if(!_bgView4){
        _bgView4 = [[UIView alloc]init];
    }
    return _bgView4;
}

-(UIImageView *)bgImg4{
    if(!_bgImg4){
        _bgImg4 = [[UIImageView alloc]init];
        _bgImg4.image = IMAGE_NAMED(@"框1");
    }
    return _bgImg4;
}

-(UIView *)bgView5{
    if(!_bgView5){
        _bgView5 = [[UIView alloc]init];
    }
    return _bgView5;
}

-(UIImageView *)bgImg5{
    if(!_bgImg5){
        _bgImg5 = [[UIImageView alloc]init];
        _bgImg5.image = IMAGE_NAMED(@"框1");
    }
    return _bgImg5;
}

-(UIImageView *)areaImg1{
    if(!_areaImg1){
        _areaImg1 = [[UIImageView alloc]init];
        _areaImg1.image = IMAGE_NAMED(@"三角形");
    }
    return _areaImg1;
}

-(UILabel *)areaLabel1{
    if(!_areaLabel1){
        _areaLabel1 = [[UILabel alloc]init];
        _areaLabel1.textColor = UICOLOR_WITH_RGBINT(0x4da8fc);
        _areaLabel1.text = @"+86";
        _areaLabel1.font = FONT(customFontName, FFont_16);
    }
    return _areaLabel1;
}

-(UITextField *)phoneTF1{
    if(!_phoneTF1){
        _phoneTF1 = [[UITextField alloc]init];
        _phoneTF1.tintColor = UICOLOR_WITH_RGBINT(0x4da8fc);
        _phoneTF1.textColor = CFontColor1;
        _phoneTF1.font = FONT(customFontName, FFont_14);
        _phoneTF1.placeholder = @"输入手机号码";
        _phoneTF1.keyboardType = UIKeyboardTypeNumberPad;
        
    }
    return _phoneTF1;
}

-(UITextField *)passWordTF{
    if(!_passWordTF){
        _passWordTF = [[UITextField alloc]init];
        _passWordTF.tintColor = UICOLOR_WITH_RGBINT(0x4da8fc);
        _passWordTF.textColor = CFontColor1;
        _passWordTF.font = FONT(customFontName, FFont_14);
        _passWordTF.placeholder = @"输入密码";
        _passWordTF.secureTextEntry = YES;
        
    }
    return _passWordTF;
}

-(UIButton *)loginBtn{
    if(!_loginBtn){
        _loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_loginBtn setBackgroundImage:IMAGE_NAMED(@"登录") forState:UIControlStateNormal];
        [_loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
        [_loginBtn.titleLabel setFont:FONT(customFontName, 15)];
        [_loginBtn addTarget:self action:@selector(loginBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _loginBtn;
}

-(UIButton *)forgetPassBtn{
    if(!_forgetPassBtn){
        _forgetPassBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_forgetPassBtn setTitleColor:UICOLOR_WITH_RGBINT(0x999999) forState:UIControlStateNormal];
        [_forgetPassBtn setTitle:@"忘记密码" forState:UIControlStateNormal];
        [_forgetPassBtn.titleLabel setFont:FONT(customFontName, 13)];
        [_forgetPassBtn addTarget:self action:@selector(forgetPassBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _forgetPassBtn;
}



@end
